<template>
  <div ref="wrapper" class="wrapper">
    <div style="transform: translateZ(0px)" class="content">
      <slot></slot>
    </div>
  </div>
</template>

<script>
import BScroll from "better-scroll";

export default {
  name: "scroller",
  data() {
    return {
      scroller: null,
    };
  },
  //接收父组件来的值
  props: {
    probeType: {
      type: Number,
      default: 0,
    },
  },
  mounted() {
        this.scroller = new BScroll(this.$refs.wrapper, {
          probeType: this.probeType,
          pullUpLoad: {
            threshold: 90,
            stop: 0,
          },
          click: true,
          pullDownRefresh: true
        });
        this.scroller.on("scroll", (postion) => {
          //console.log(postion);
          this.$emit("scroll", postion);
        });
        this.scroller.on("pullingUp", () => {
          this.$emit("pullingUp");
        });
        this.scroller.on("pullingDown", () => {
          this.$emit("pullingDown");
        });
  },
  updated() {
    this.$nextTick(() => {
      this.refresh();
    });
  },
  methods: {
    scrollTo(x, y, time = 300) {
      this.scroller.scrollTo(0, 0, time);
    },
    refresh() {
      this.scroller.refresh();
    },
    finishPullUp() {
      this.scroller.finishPullUp();
    },
    finishPullDown() {
      this.scroller.finishPullDown();
    },
  },
};
</script>

<style scoped>
</style>
